package com.imy.alscript;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.imy.virtual.client.core.VirtualCore;

import java.util.List;

public class InstallListAdapter extends BaseSimpleListAdapter<PackageInfo, InstallListAdapter.Holder> {
  private Context mContext;
  private List mList;

  public InstallListAdapter(Context context, List<PackageInfo> infos) {
    super(context, infos);
  }

  @Override
  protected void bindView(int position, Holder holder, View convertView, PackageInfo bean) {

    String packageName = bean.packageName;
    holder.packageTv.setText(packageName);

    int labelRes = bean.applicationInfo.labelRes;
    CharSequence text = VirtualCore.get().getPackageManager().getText(packageName, labelRes, bean.applicationInfo);
    Drawable applicationIcon = VirtualCore.get().getPackageManager().getApplicationIcon(bean.applicationInfo);
    holder.icon.setImageDrawable(applicationIcon);
    Log.i(TAG, "test:" + text);
    holder.nameTv.setText(text);
  }

  @Override
  protected int getLayoutId() {
    return R.layout.list_item;
  }

  @Override
  public Holder getHolder(View view) {
    return new Holder(view);
  }

  public class Holder extends BaseViewHolder {

    TextView nameTv;
    ImageView icon;
    TextView packageTv;

    public Holder(View itemView) {
      super(itemView);
      nameTv = itemView.findViewById(R.id.apk_name);
      icon = itemView.findViewById(R.id.icon_iv);
      packageTv = itemView.findViewById(R.id.package_tv);
    }
  }
}
